package com.aiclient.model;

import java.util.ArrayList;
import java.util.List;
import java.time.LocalDateTime;
import java.util.UUID;

public class Chat {
    private String id;
    private String title;
    private LocalDateTime createdAt;
    private List<Message> messages = new ArrayList<>();
    
    public Chat() {
        this.id = UUID.randomUUID().toString();
        this.createdAt = LocalDateTime.now();
        this.title = "新会话";
    }
    
    public String getId() {
        return id;
    }
    
    public void setId(String id) {
        this.id = id;
    }
    
    public String getTitle() {
        return title;
    }
    
    public void setTitle(String title) {
        this.title = title;
    }
    
    public LocalDateTime getCreatedAt() {
        return createdAt;
    }
    
    public void setCreatedAt(LocalDateTime createdAt) {
        this.createdAt = createdAt;
    }
    
    public List<Message> getMessages() {
        return messages;
    }
    
    public void setMessages(List<Message> messages) {
        this.messages = messages;
    }
    
    public void addMessage(Message message) {
        messages.add(message);
        if (messages.size() == 1 && message.getRole().equals("user")) {
            title = message.getContent().length() > 20 
                ? message.getContent().substring(0, 20) + "..."
                : message.getContent();
        }
    }
    
    @Override
    public String toString() {
        return title;
    }
} 